using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class InventorySlotController:MonoBehaviour {

	[SerializeField] int slotIndex;
	Image image;
	private void Awake() {
		image=GetComponent<Image>();
	}

	private void Update() {
		if(PlayerController.instance==null) return;
		SpriteRenderer targetSprite = null;
		if(PlayerController.instance.inventory.Count>slotIndex) {
			GameObject targetObject = PlayerController.instance.inventory[slotIndex];
			if(targetObject) targetSprite=targetObject.GetComponent<SpriteRenderer>();
		}

		if(targetSprite==null) {
			image.color=Color.clear;
		} else {
			image.color=Color.white;
			image.sprite=targetSprite.sprite;
			//image.SetNativeSize();
		}
	}

}
